﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.TeamFoundation.WorkItemTracking.Client;
using CDSBDemandControl.Model;

namespace CDSBDemandControlService.Translator
{
    public class XMLModelTranslate
    {
        private XMLModelTranslate()
        {
        
        }

        public static XMLDemandModel Translate(WorkItem workItem)
        {
            if (workItem == null) return null;

            XMLDemandModel demanda = new XMLDemandModel();

            demanda.ID = workItem.Id.ToString();
            demanda.Title = workItem.Title;
            demanda.State = workItem.State;
            demanda.WorkItemType = workItem.Type.Name;
            demanda.Project = workItem.Project.Name;
            demanda.Reason = workItem.Reason;
            demanda.CreatedBy = workItem.CreatedBy;
            demanda.AssignedTo = workItem.Fields.Contains("Assigned To") && workItem.Fields["Assigned To"].Value != null ? workItem.Fields["Assigned To"].Value.ToString() : "";
            demanda.EstimatedHours = workItem.Fields.Contains("Horas Previstas") && workItem.Fields["Horas Previstas"].Value != null ? Convert.ToInt32(workItem.Fields["Horas Previstas"].Value) : 0;
            demanda.UsedHours = workItem.Fields.Contains("Horas Realizadas") && workItem.Fields["Horas Realizadas"].Value != null ? Convert.ToInt32(workItem.Fields["Horas Realizadas"].Value) : 0;
            demanda.Remedy = workItem.Fields.Contains("Remedy") && workItem.Fields["Remedy"].Value != null ? workItem.Fields["Remedy"].Value.ToString() : null;
            demanda.Justification = workItem.Fields.Contains("Atrasos") && workItem.Fields["Atrasos"].Value != null ? workItem.Fields["Atrasos"].Value.ToString() : null;
            demanda.Description = "" + workItem.Fields["Description"].Value;
            demanda.IsSimultaneous = workItem.Fields.Contains("Simultanea") && workItem.Fields["Simultanea"].Value != null && workItem.Fields["Simultanea"].Value.ToString().ToLower() == "sim" ? true : false;
            demanda.Revision = InvolvedTranslator.Translate(workItem.Revisions);

            #region Data de Entrada na Fila

            // Para TaskDesenv, a data que entrou na fila é o campo criado para esse fim pela equipe de Release Manager
            if (workItem.Fields.Contains("Data Inc Fila") && workItem.Fields["Data Inc Fila"].Value != null)
                demanda.DataIncFila = (DateTime)workItem.Fields["Data Inc Fila"].Value;
            // Para Bug vai ser a data em que o mesmo ficou ativo.
            else if (workItem.Fields.Contains("Activated Date") && workItem.Fields["Activated Date"].Value != null)
                demanda.DataIncFila = (DateTime)workItem.Fields["Activated Date"].Value;

            #endregion

            demanda.Origin = workItem.Fields.Contains("Origem") && workItem.Fields["Origem"].Value != null ? workItem.Fields["Origem"].Value.ToString() : "";
            demanda.Gravity = workItem.Fields.Contains("Gravidade") && workItem.Fields["Gravidade"].Value != null ? workItem.Fields["Gravidade"].Value.ToString() : "";
            demanda.Priority = workItem.Fields.Contains("Rank") && workItem.Fields["Rank"].Value != null ? workItem.Fields["Rank"].Value.ToString() : "";

            if (workItem.Fields.Contains("Start Date") && workItem.Fields["Start Date"].Value != null) demanda.EstimatedStart = (DateTime)workItem.Fields["Start Date"].Value;
            if (workItem.Fields.Contains("Finish Date") && workItem.Fields["Finish Date"].Value != null) demanda.EstimatedConclude = (DateTime)workItem.Fields["Finish Date"].Value;
            if (workItem.Fields.Contains("Inicio Realizado") && workItem.Fields["Inicio Realizado"].Value != null) demanda.Start = (DateTime)workItem.Fields["Inicio Realizado"].Value;
            if (workItem.Fields.Contains("Termino Realizado") && workItem.Fields["Termino Realizado"].Value != null) demanda.Conclude = (DateTime)workItem.Fields["Termino Realizado"].Value;

            return demanda;
        }

        public static XMLDemandModel TranslateScenario(WorkItem workItem)
        {
            if (workItem == null) return null;

            XMLDemandModel demanda = new XMLDemandModel();

            demanda.ID = workItem.Id.ToString();
            demanda.Title = workItem.Title;
            demanda.State = workItem.State;
            demanda.WorkItemType = workItem.Type.Name;
            demanda.Project = workItem.Project.Name;
            demanda.Reason = workItem.Reason;
            demanda.CreatedBy = workItem.CreatedBy;
            demanda.AssignedTo = workItem.Fields.Contains("Assigned To") && workItem.Fields["Assigned To"].Value != null ? workItem.Fields["Assigned To"].Value.ToString() : "";
            demanda.EstimatedHours = workItem.Fields.Contains("Horas Previstas") && workItem.Fields["Horas Previstas"].Value != null ? Convert.ToInt32(workItem.Fields["Horas Previstas"].Value) : 0;
            demanda.UsedHours = workItem.Fields.Contains("Horas Realizadas") && workItem.Fields["Horas Realizadas"].Value != null ? Convert.ToInt32(workItem.Fields["Horas Realizadas"].Value) : 0;
            demanda.Remedy = workItem.Fields.Contains("Remedy") && workItem.Fields["Remedy"].Value != null ? workItem.Fields["Remedy"].Value.ToString() : null;
            demanda.Revision = InvolvedTranslator.Translate(workItem.Revisions);

            #region Data de Entrada na Fila

            // Para TaskDesenv, a data que entrou na fila é o campo criado para esse fim pela equipe de Release Manager
            if (workItem.Fields.Contains("Data Inc Fila") && workItem.Fields["Data Inc Fila"].Value != null)
                demanda.DataIncFila = (DateTime)workItem.Fields["Data Inc Fila"].Value;
            // Para Bug vai ser a data em que o mesmo ficou ativo.
            else if (workItem.Fields.Contains("Activated Date") && workItem.Fields["Activated Date"].Value != null)
                demanda.DataIncFila = (DateTime)workItem.Fields["Activated Date"].Value;

            #endregion

            demanda.Origin = workItem.Fields.Contains("Origem") && workItem.Fields["Origem"].Value != null ? workItem.Fields["Origem"].Value.ToString() : "";
            demanda.Gravity = workItem.Fields.Contains("Gravidade") && workItem.Fields["Gravidade"].Value != null ? workItem.Fields["Gravidade"].Value.ToString() : "";
            demanda.Priority = workItem.Fields.Contains("Rank") && workItem.Fields["Rank"].Value != null ? workItem.Fields["Rank"].Value.ToString() : "";
            demanda.Description = "" + workItem.Fields["Description"].Value;

            object obj = null;

            #region Em avaliação de demanda

            //Este Try foi implementado devido ao fato de que nem todos os AreaPath dos Sites possuem a aba Em avaliação de Demanda.
            //Assim que esta for adicionada basta retirar o conteúdo do bloco try para fora
            //5/7/2010 - 13:08 por (p-rcustodio)

            try
            {
                if ((obj = workItem.Fields["Bovespa.Sinacor.AssessingDemand.Planned.StartDate"].Value) != null && obj.ToString() != string.Empty)
                    demanda.AssessingDemandPlannedStartDate = DateTime.Parse(obj.ToString());

                if ((obj = workItem.Fields["Bovespa.Sinacor.AssessingDemand.Planned.EndDate"].Value) != null && obj.ToString() != string.Empty)
                    demanda.AssessingDemandPlannedEndDate = DateTime.Parse(obj.ToString());

                if ((obj = workItem.Fields["Bovespa.Sinacor.AssessingDemand.Planned.Time"].Value) != null && obj.ToString() != string.Empty)
                    demanda.AssessingDemandPlannedTime = Decimal.Parse(obj.ToString());

                if ((obj = workItem.Fields["Bovespa.Sinacor.AssessingDemand.Realized.StartDate"].Value) != null && obj.ToString() != string.Empty)
                    demanda.AssessingDemandRealizedStartDate = DateTime.Parse(obj.ToString());

                if ((obj = workItem.Fields["Bovespa.Sinacor.AssessingDemand.Realized.EndDate"].Value) != null && obj.ToString() != string.Empty)
                    demanda.AssessingDemandRealizedEndDate = DateTime.Parse(obj.ToString());

                if ((obj = workItem.Fields["Bovespa.Sinacor.AssessingDemand.Realized.Time"].Value) != null && obj.ToString() != string.Empty)
                    demanda.AssessingDemandRealizedTime = Decimal.Parse(obj.ToString());
            }
            catch (Exception)
            {
                demanda.AssessingDemandPlannedStartDate = DateTime.MinValue;
                demanda.AssessingDemandPlannedEndDate = DateTime.MinValue;
                demanda.AssessingDemandPlannedTime = 0;
                demanda.AssessingDemandRealizedStartDate = DateTime.MinValue;
                demanda.AssessingDemandRealizedEndDate = DateTime.MinValue;
                demanda.AssessingDemandRealizedTime = 0;    
            }

            #endregion

            #region Especificação(Geral)

            if ((obj = workItem.Fields["Bovespa.Sinacor.Specification.General.Planned.StartDate"].Value) != null && obj.ToString() != string.Empty)
                demanda.GeneralPlannedStartDate = DateTime.Parse(obj.ToString());

            if ((obj = workItem.Fields["Bovespa.Sinacor.Specification.General.Planned.EndDate"].Value) != null && obj.ToString() != string.Empty)
                demanda.GeneralPlannedEndDate = DateTime.Parse(obj.ToString());

            if ((obj = workItem.Fields["Bovespa.Sinacor.Specification.General.Planned.Time"].Value) != null && obj.ToString() != string.Empty)
                demanda.GeneralPlannedTime = Decimal.Parse(obj.ToString());

            if ((obj = workItem.Fields["Bovespa.Sinacor.Specification.General.Planned.Complexity"].Value) != null && obj.ToString() != string.Empty)
                demanda.GeneralPlannedComplexity = (Complexity)System.Enum.Parse(typeof(Complexity), obj.ToString());

            if ((obj = workItem.Fields["Bovespa.Sinacor.Specification.General.Realized.StartDate"].Value) != null && obj.ToString() != string.Empty)
                demanda.GeneralRealizedStartDate = DateTime.Parse(obj.ToString());

            if ((obj = workItem.Fields["Bovespa.Sinacor.Specification.General.Realized.EndDate"].Value) != null && obj.ToString() != string.Empty)
                demanda.GeneralRealizedEndDate = DateTime.Parse(obj.ToString());

            if ((obj = workItem.Fields["Bovespa.Sinacor.Specification.General.Realized.Time"].Value) != null && obj.ToString() != string.Empty)
                demanda.GeneralRealizedTime = Decimal.Parse(obj.ToString());

            if ((obj = workItem.Fields["Bovespa.Sinacor.Specification.General.Realized.Evolutions"].Value) != null && obj.ToString() != string.Empty)
                demanda.GeneralRealizedEvolutions = Int32.Parse(obj.ToString());

            #endregion

            #region Especificação(Artefatos)(Artefatos de Testes)

            if ((obj = workItem.Fields["Bovespa.Sinacor.Specification.MED.RTF.Planned.StartDate"].Value) != null && obj.ToString() != string.Empty)
                demanda.MEDRTFPlannedStartDate = DateTime.Parse(obj.ToString());

            if ((obj = workItem.Fields["Bovespa.Sinacor.Specification.MED.RTF.Planned.EndDate"].Value) != null && obj.ToString() != string.Empty)
                demanda.MEDRTFPlannedEndDate = DateTime.Parse(obj.ToString());

            if ((obj = workItem.Fields["Bovespa.Sinacor.Specification.MED.RTF.Planned.Time"].Value) != null && obj.ToString() != string.Empty)
                demanda.MEDRTFPlannedTime = Decimal.Parse(obj.ToString());

            if ((obj = workItem.Fields["Bovespa.Sinacor.Specification.MED.RTF.Planned.Mass.Data"].Value) != null && obj.ToString() != string.Empty)
                demanda.MEDRTFPlannedMassData = obj.ToString().Contains("S") || obj.ToString().Contains("Y");

            if ((obj = workItem.Fields["Bovespa.Sinacor.Specification.MED.RTF.Realized.StartDate"].Value) != null && obj.ToString() != string.Empty)
                demanda.MEDRTFRealizedStartDate = DateTime.Parse(obj.ToString());

            if ((obj = workItem.Fields["Bovespa.Sinacor.Specification.MED.RTF.Realized.EndDate"].Value) != null && obj.ToString() != string.Empty)
                demanda.MEDRTFRealizedEndDate = DateTime.Parse(obj.ToString());

            if ((obj = workItem.Fields["Bovespa.Sinacor.Specification.MED.RTF.Realized.Time"].Value) != null && obj.ToString() != string.Empty)
                demanda.MEDRTFRealizedTime = Decimal.Parse(obj.ToString());

            if ((obj = workItem.Fields["Bovespa.Sinacor.Specification.MED.RTF.Realized.Evolutions"].Value) != null && obj.ToString() != string.Empty)
                demanda.MEDRTFRealizedEvolutions = Int32.Parse(obj.ToString());

            #endregion

            #region Especificação(Artefatos)(Diagramação)

            if ((obj = workItem.Fields["Bovespa.Sinacor.Specification.XAML.Planned.StartDate"].Value) != null && obj.ToString() != string.Empty)
                demanda.XAMLPlannedStartDate = DateTime.Parse(obj.ToString());

            if ((obj = workItem.Fields["Bovespa.Sinacor.Specification.XAML.Planned.EndDate"].Value) != null && obj.ToString() != string.Empty)
                demanda.XAMLPlannedEndDate = DateTime.Parse(obj.ToString());

            if ((obj = workItem.Fields["Bovespa.Sinacor.Specification.XAML.Planned.Time"].Value) != null && obj.ToString() != string.Empty)
                demanda.XAMLPlannedTime = Decimal.Parse(obj.ToString());

            if ((obj = workItem.Fields["Bovespa.Sinacor.Specification.XAML.Realized.StartDate"].Value) != null && obj.ToString() != string.Empty)
                demanda.XAMLRealizedStartDate = DateTime.Parse(obj.ToString());

            if ((obj = workItem.Fields["Bovespa.Sinacor.Specification.XAML.Realized.EndDate"].Value) != null && obj.ToString() != string.Empty)
                demanda.XAMLRealizedEndDate = DateTime.Parse(obj.ToString());

            if ((obj = workItem.Fields["Bovespa.Sinacor.Specification.XAML.Realized.Time"].Value) != null && obj.ToString() != string.Empty)
                demanda.XAMLRealizedTime = Decimal.Parse(obj.ToString());

            if ((obj = workItem.Fields["Bovespa.Sinacor.Specification.XAML.Realized.Evolutions"].Value) != null && obj.ToString() != string.Empty)
                demanda.XAMLRealizedEvolutions = Int32.Parse(obj.ToString());

            #endregion

            #region Arquitetura

            if ((obj = workItem.Fields["Bovespa.Sinacor.Architecture.Planned.StartDate"].Value) != null && obj.ToString() != string.Empty)
                demanda.ArchitecturePlannedStartDate = DateTime.Parse(obj.ToString());

            if ((obj = workItem.Fields["Bovespa.Sinacor.Architecture.Planned.EndDate"].Value) != null && obj.ToString() != string.Empty)
                demanda.ArchitecturePlannedEndDate = DateTime.Parse(obj.ToString());

            if ((obj = workItem.Fields["Bovespa.Sinacor.Architecture.Planned.Time"].Value) != null && obj.ToString() != string.Empty)
                demanda.ArchitecturePlannedTime = Decimal.Parse(obj.ToString());

            if ((obj = workItem.Fields["Bovespa.Sinacor.Architecture.Planned.Complexity"].Value) != null && obj.ToString() != string.Empty)
                demanda.ArchitecturePlannedComplexity = (Complexity)System.Enum.Parse(typeof(Complexity), obj.ToString());

            if ((obj = workItem.Fields["Bovespa.Sinacor.Architecture.Realized.StartDate"].Value) != null && obj.ToString() != string.Empty)
                demanda.ArchitectureRealizedStartDate = DateTime.Parse(obj.ToString());

            if ((obj = workItem.Fields["Bovespa.Sinacor.Architecture.Realized.EndDate"].Value) != null && obj.ToString() != string.Empty)
                demanda.ArchitectureRealizedEndDate = DateTime.Parse(obj.ToString());

            if ((obj = workItem.Fields["Bovespa.Sinacor.Architecture.Realized.Time"].Value) != null && obj.ToString() != string.Empty)
                demanda.ArchitectureRealizedTime = Decimal.Parse(obj.ToString());

            if ((obj = workItem.Fields["Bovespa.Sinacor.Architecture.Realized.Evolutions"].Value) != null && obj.ToString() != string.Empty)
                demanda.ArchitectureRealizedEvolutions = Int32.Parse(obj.ToString());

            #endregion

            #region Desenvolvimento

            if ((obj = workItem.Fields["Bovespa.Sinacor.Development.Planned.StartDate"].Value) != null && obj.ToString() != string.Empty)
                demanda.DevelopmentPlannedStartDate = DateTime.Parse(obj.ToString());

            if ((obj = workItem.Fields["Bovespa.Sinacor.Development.Planned.EndDate"].Value) != null && obj.ToString() != string.Empty)
                demanda.DevelopmentPlannedEndDate = DateTime.Parse(obj.ToString());

            if ((obj = workItem.Fields["Bovespa.Sinacor.Development.Planned.Time"].Value) != null && obj.ToString() != string.Empty)
                demanda.DevelopmentPlannedTime = Decimal.Parse(obj.ToString());

            if ((obj = workItem.Fields["Bovespa.Sinacor.Development.Planned.Complexity"].Value) != null && obj.ToString() != string.Empty)
                demanda.DevelopmentPlannedComplexity = (Complexity)System.Enum.Parse(typeof(Complexity), obj.ToString());

            if ((obj = workItem.Fields["Bovespa.Sinacor.Development.Realized.StartDate"].Value) != null && obj.ToString() != string.Empty)
                demanda.DevelopmentRealizedStartDate = DateTime.Parse(obj.ToString());

            if ((obj = workItem.Fields["Bovespa.Sinacor.Development.Realized.EndDate"].Value) != null && obj.ToString() != string.Empty)
                demanda.DevelopmentRealizedEndDate = DateTime.Parse(obj.ToString());

            if ((obj = workItem.Fields["Bovespa.Sinacor.Development.Realized.Time"].Value) != null && obj.ToString() != string.Empty)
                demanda.DevelopmentRealizedTime = Decimal.Parse(obj.ToString());

            if ((obj = workItem.Fields["Bovespa.Sinacor.Development.Realized.Evolutions"].Value) != null && obj.ToString() != string.Empty)
                demanda.DevelopmentRealizedEvolutions = Int32.Parse(obj.ToString());

            #endregion

            #region Testes

            if ((obj = workItem.Fields["Bovespa.Sinacor.Tests.Planned.StartDate"].Value) != null && obj.ToString() != string.Empty)
                demanda.TestsPlannedStartDate = DateTime.Parse(obj.ToString());

            if ((obj = workItem.Fields["Bovespa.Sinacor.Tests.Planned.EndDate"].Value) != null && obj.ToString() != string.Empty)
                demanda.TestsPlannedEndDate = DateTime.Parse(obj.ToString());

            if ((obj = workItem.Fields["Bovespa.Sinacor.Tests.Planned.Time"].Value) != null && obj.ToString() != string.Empty)
                demanda.TestsPlannedTime = Decimal.Parse(obj.ToString());

            if ((obj = workItem.Fields["Bovespa.Sinacor.Tests.Realized.StartDate"].Value) != null && obj.ToString() != string.Empty)
                demanda.TestsRealizedStartDate = DateTime.Parse(obj.ToString());

            if ((obj = workItem.Fields["Bovespa.Sinacor.Tests.Realized.EndDate"].Value) != null && obj.ToString() != string.Empty)
                demanda.TestsRealizedEndDate = DateTime.Parse(obj.ToString());

            if ((obj = workItem.Fields["Bovespa.Sinacor.Tests.Realized.Time"].Value) != null && obj.ToString() != string.Empty)
                demanda.TestsRealizedTime = Decimal.Parse(obj.ToString());

            if ((obj = workItem.Fields["Microsoft.VSTS.Test.TestCiclo"].Value) != null && obj.ToString() != string.Empty)
                demanda.TestCiclo = Int32.Parse(obj.ToString());

            #endregion

            #region Aceite

            if ((obj = workItem.Fields["Bovespa.Sinacor.Accepted.Planned.StartDate"].Value) != null && obj.ToString() != string.Empty)
                demanda.AcceptedPlannedStartDate = DateTime.Parse(obj.ToString());

            if ((obj = workItem.Fields["Bovespa.Sinacor.Accepted.Planned.EndDate"].Value) != null && obj.ToString() != string.Empty)
                demanda.AcceptedPlannedEndDate = DateTime.Parse(obj.ToString());

            if ((obj = workItem.Fields["Bovespa.Sinacor.Accepted.Planned.Time"].Value) != null && obj.ToString() != string.Empty)
                demanda.AcceptedPlannedTime = Decimal.Parse(obj.ToString());

            if ((obj = workItem.Fields["Bovespa.Sinacor.Accepted.Realized.StartDate"].Value) != null && obj.ToString() != string.Empty)
                demanda.AcceptedRealizedStartDate = DateTime.Parse(obj.ToString());

            if ((obj = workItem.Fields["Bovespa.Sinacor.Accepted.Realized.EndDate"].Value) != null && obj.ToString() != string.Empty)
                demanda.AcceptedRealizedEndDate = DateTime.Parse(obj.ToString());

            if ((obj = workItem.Fields["Bovespa.Sinacor.Accepted.Realized.Time"].Value) != null && obj.ToString() != string.Empty)
                demanda.AcceptedRealizedTime = Decimal.Parse(obj.ToString());

            if ((obj = workItem.Fields["Bovespa.Sinacor.Accepted.Realized.Evolutions"].Value) != null && obj.ToString() != string.Empty)
                demanda.AcceptedRealizedEvolutions = Int32.Parse(obj.ToString());

            #endregion

            #region Release

            if ((obj = workItem.Fields["Bovespa.Sinacor.Release.Planned.StartDate"].Value) != null && obj.ToString() != string.Empty)
                demanda.ReleasePlannedStartDate = DateTime.Parse(obj.ToString());

            if ((obj = workItem.Fields["Bovespa.Sinacor.Release.Planned.EndDate"].Value) != null && obj.ToString() != string.Empty)
                demanda.ReleasePlannedEndDate = DateTime.Parse(obj.ToString());

            if ((obj = workItem.Fields["Bovespa.Sinacor.Release.Planned.Time"].Value) != null && obj.ToString() != string.Empty)
                demanda.ReleasePlannedTime = Decimal.Parse(obj.ToString());

            if ((obj = workItem.Fields["Bovespa.Sinacor.Release.Realized.StartDate"].Value) != null && obj.ToString() != string.Empty)
                demanda.ReleaseRealizedStartDate = DateTime.Parse(obj.ToString());

            if ((obj = workItem.Fields["Bovespa.Sinacor.Release.Realized.EndDate"].Value) != null && obj.ToString() != string.Empty)
                demanda.ReleaseRealizedEndDate = DateTime.Parse(obj.ToString());

            if ((obj = workItem.Fields["Bovespa.Sinacor.Release.Realized.Time"].Value) != null && obj.ToString() != string.Empty)
                demanda.ReleaseRealizedTime = Decimal.Parse(obj.ToString());

            if ((obj = workItem.Fields["Bovespa.Sinacor.Release.Realized.Evolutions"].Value) != null && obj.ToString() != string.Empty)
                demanda.ReleaseRealizedEvolutions = Int32.Parse(obj.ToString());

            #endregion

            return demanda;
        }


        public static ScenarioModel TranslateScenario(WorkItem workItem, string related)
        {
            ScenarioModel mod = new ScenarioModel();
            mod.ID = workItem.Id;
            mod.Project = workItem.Project.Name;
            mod.Title = workItem.Title;
            mod.AssignedTo = workItem.Fields.Contains("Assigned To") && workItem.Fields["Assigned To"].Value != null ? workItem.Fields["Assigned To"].Value.ToString() : "";
            mod.Related = related;
            mod.Status = workItem.State;

            return mod;

        }

        public static void AddTaskDesenvToScenario(ScenarioModel parent, WorkItem child)
        {
            TaskDesenvModel neo = new TaskDesenvModel();

            neo.ID = child.Id;
            neo.Title = child.Title;

            if (child.Fields.Contains("Inicio Realizado") && child.Fields["Inicio Realizado"].Value != null)
            {
                neo.Start = DateTime.Parse(child.Fields["Inicio Realizado"].Value.ToString());
            }
            else
                neo.Start = null;

            if (child.Fields.Contains("Termino Realizado") && child.Fields["Termino Realizado"].Value != null)
            {
                neo.Conclude = DateTime.Parse(child.Fields["Termino Realizado"].Value.ToString());
            }
            else
                neo.Conclude = null;

            if (child.Fields.Contains("Start Date") && child.Fields["Start Date"].Value != null)
            {
                neo.EstimatedStart = DateTime.Parse(child.Fields["Start Date"].Value.ToString());
            }
            else
                neo.EstimatedStart = null;

            if (child.Fields.Contains("Finish Date") && child.Fields["Finish Date"].Value != null)
            {
                neo.EstimatedConclude = DateTime.Parse(child.Fields["Finish Date"].Value.ToString());
            }
            else
                neo.EstimatedConclude = null;

            neo.AssignedTo = child.Fields.Contains("Assigned To") && child.Fields["Assigned To"].Value != null ? child.Fields["Assigned To"].Value.ToString() : string.Empty;
            neo.Status = child.State;

            parent.RelatedLinks.Add(neo);
        }
    }
}